package util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class FileUtils {
	
	public static void save(String savePath,InputStream inputStream,OutputStream outputStream) throws IOException {
		File file = new File(savePath);
		if (!file.exists()) {
			File parent = new File(file.getParent());
			if (!parent.exists()) {
				parent.mkdirs();
				parent.setReadable(true);
				parent.setWritable(true);
			}
		}
		outputStream = new FileOutputStream(savePath);
		byte[] buf = new byte[1024];
		int len = 0;
		while((len=inputStream.read(buf))!=-1) {
			outputStream.write(buf, 0, len);
		}
	}

}
